package com.itheima.xmy.Demo;

public class Student {
    private  String name;
    private  String sex;
    private int age;

    public Student() {
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public String getSex() {
        return sex;
    }
    //        在性别的set方法中判断是否是男/女，如果不是则抛出：性别异常<br />

    public void setSex(String sex) {
        if(sex.equals("男")||sex.equals("女")){
            this.sex = sex;
        }else {
            throw new SexException("您输入的性别有问题："+sex);
        }
    }

    public int getAge() {
        return age;
    }
//        在年龄的set方法中判断年龄是否是15--50之间，如果不是则抛出：年龄异常
    public void setAge(int age) {
        if(age>=15&&age<=50){
            this.age = age;
        }else {
            throw new AgeException("您输入的年龄有问题："+age);
        }
    }

    public Student(String name, String sex, int age) {
        this.name = name;
        this.sex = sex;
        this.age = age;
    }
}
